/*
 * @Author: FMC
 * @Date: 2024-07-09 20:48:13
 * @LastEditors: FMC
 * @LastEditTime: 2024-07-11 00:59:46
 * @FilePath: \three-run-game\src\views\react-three\meshes\block-end\block-end.jsx
 * @Description:
 */
import { sharedBoxGeometry } from "../../../../common/geometry/geometry.js";
import { shadedGround1Material } from "../../../../common/material/material.js";
import { useLoader } from "@react-three/fiber";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
import { Suspense } from "react";
import { RigidBody } from "@react-three/rapier";
import { Center, Float, Text3D, useTexture, Helper,Text } from "@react-three/drei";
import { useControls } from "leva";
// 预加载
// useGLTF.preload("model/coin.gltf");
/**
 *
 * 终点
 */
function BlockEnd({ position = [0, 0, 0] }) {
  const matcap = useTexture(window.resourceBaseUrl+"/matcaps/5.png");
  return (
    <>
      <group position={position}>
        <mesh
          position={[0, -0.1, 0]}
          scale={[4, 0.2, 4]}
          geometry={sharedBoxGeometry}
          material={shadedGround1Material}
          receiveShadow
        ></mesh>
        <Float floatIntensity={0.25} rotationIntensity={0.25}>
          {/* <Text3D
            font="/fonts/cn.json"
            position={[-0.26, 1, 1.5]}
            scale={[0.2, 0.2, 0.2]}
            curveSegments={12}
            bevelEnabled
            bevelThickness={0.05}
            bevelSize={0.02}
            bevelOffset={0}
            bevelSegments={5}
          >
            终点
            <meshMatcapMaterial matcap={matcap} />
          </Text3D> */}
          <Text
            font="/fonts/sans-serif.normal.400.woff"
            fontSize={0.25}
            position={[0,1.5,2]}
          >
            终点
          </Text>
        </Float>
        <Suspense>
          <RigidBody
            type="fixed"
            colliders="hull"
            restitution={0.2}
            friction={0}
          >
            <Model scale={[1.5, 1.5, 1.5]} position-y={1.0} />
          </RigidBody>
        </Suspense>
      </group>
    </>
  );
}
function Model(props) {
  const model = useLoader(GLTFLoader, "model/coin.gltf", (loader) => {
    const dracoLoader = new DRACOLoader();
    dracoLoader.setDecoderPath("draco/");
    loader.setDRACOLoader(dracoLoader);
  });
  // 设置阴影
  model.scene.traverse((item) => {
    if (item.isMesh) {
      item.castShadow = true;
      // item.receiveShadow = true;
    }
  });
  return (
    <>
      <primitive object={model.scene} {...props}></primitive>
    </>
  );
}
export default BlockEnd;
